<template>
  <div>
    <router-link class="detail-header" to="/" v-if="showAbs">
      <div class="iconfont back-icon">&#xe624;</div>
    </router-link>
    <div class="detail-flex" v-if="!showAbs" :style="opacityStyle">
        景点详情
        <router-link to="/">
          <div class="iconfont city-icon">&#xe624;</div>
        </router-link>
    </div>
  </div>
</template>
<script>
export default {
  name: 'detailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 60) {
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>
<style lang="stylus" scoped>
  @import "~styles/varibles";
  .detail-header
    position: absolute
    top: .2rem
    left: .2rem
    width: .8rem
    height: .8rem
    border-radius: .4rem
    background: rgba(0, 0, 0, 0.6)
    .back-icon
      color: #fff
      line-height: .8rem
      text-align: center
  .detail-flex
     z-index: 99
     position: fixed
     top: 0
     width: $maxWidth
     height: .86rem
     line-height: .86rem
     background: $bgColor
     color: $colorFFF
     text-align: center
     font-size: .32rem
     .city-icon
       width: 0.64rem
       position: absolute
       top: 0
       left: 0
       color: $colorFFF
</style>
